package com.game.majiang.logic;

import com.game.majiang.config.CreateStructrue;
import com.game.majiang.vo.RoomConfigVo;
import com.game.server.system.AbstractRoom;
import com.game.server.system.AbstractTable;
import com.game.server.util.Util;
import com.timing.RoomTask;

import lombok.Getter;

/**
 * @author 
 * 
 */
@Getter
public abstract class LogicRoom extends AbstractRoom {

    public LogicRoom(RoomConfigVo vo) {
		super(vo.getId());
		this.name = vo.getName();
		this.type = vo.getRoomtype();
		this.player_limit = vo.getPlayerlimit();
		this.id=vo.getId();
		new RoomTask(this);
	}
   
  
	public synchronized int gettableid()
	{
		
		int number =0;	
		do {			
			number = Util.random(100000, 1000000);
			boolean temp=false;
			for (AbstractRoom room : LogicServer.getInstance().getRooms()) {
				for(AbstractTable t:room.getTables()){				
					if(number==t.getID()){
						number=0;
						temp = true;
						break;
					}
				}
				if(temp){
					break;
				}
			}
			
		} while (number==0);
		
		return  number;
	}
	
    /** room id */
    protected short id;
    
    /** 名字 */
    protected String name;
    
    /**
     *人数限制
     */
    protected int player_limit;
    
    public abstract LogicTable createTable(CreateStructrue struct);
}
